<?php

namespace addons\weixin;

use app\common\library\Menu;
use think\Addons;

/**
 * 微信管理插件
 */
class Weixin extends Addons
{
    /**
     * 插件安装方法
     * @return bool
     */
    public function install()
    {
        $menu = [
            [
                'name'    => 'weixin',
                'title'   => '微信公众号管理',
                'icon'    => 'fa fa-weixin',
                'sublist' => [
                    [
                        'name'    => 'weixin/config',
                        'title'   => '应用配置',
                        'extend'  => 'padding-left: 15px;',
                        'icon'    => 'fa fa-angle-double-right',
                        'sublist' => [
                            ['name' => 'weixin/config/index', 'title' => '查看'],
                            ['name' => 'weixin/config/edit',  'title' => '编辑']
                        ]
                    ],
                    [
                        'name'    => 'weixin/menus',
                        'title'   => '菜单管理',
                        'extend'  => 'padding-left: 15px;',
                        'icon'    => 'fa fa-angle-double-right',
                        'sublist' => [
                            ['name' => 'weixin/menus/index', 'title' => '查看'],
                            ['name' => 'weixin/menus/sync',  'title' => '同步']
                        ]
                    ],
                    [
                        'name'    => 'weixin/template',
                        'title'   => '模板消息',
                        'extend'  => 'padding-left: 15px;',
                        'icon'    => 'fa fa-angle-double-right',
                        'sublist' => [
                            ['name' => 'weixin/template/index', 'title' => '查看'],
                            ['name' => 'weixin/template/add',   'title' => '添加'],
                            ['name' => 'weixin/template/edit',  'title' => '编辑'],
                            ['name' => 'weixin/template/multi', 'title' => '批量更新'],
                            ['name' => 'weixin/template/del',   'title' => '删除']
                        ]
                    ],
                    [
                        'name'    => 'weixin/reply',
                        'title'   => '回复管理',
                        'extend'  => 'padding-left: 15px;',
                        'icon'    => 'fa fa-angle-double-right',
                        'sublist' => [
                            ['name' => 'weixin/reply/index', 'title' => '查看'],
                            ['name' => 'weixin/reply/add', 'title' => '新增'],
                            ['name' => 'weixin/reply/edit', 'title' => '编辑'],
                            ['name' => 'weixin/reply/del', 'title' => '删除'],
                            ['name' => 'weixin/reply/multi', 'title' => '批量更新']
                        ]
                    ],
                    [
                        'name'    => 'weixin/news',
                        'title'   => '图文消息',
                        'extend'  => 'padding-left: 15px;',
                        'icon'    => 'fa fa-angle-double-right',
                        'sublist' => [
                            ['name' => 'weixin/news/index', 'title' => '查看'],
                            ['name' => 'weixin/news/add', 'title' => '新增'],
                            ['name' => 'weixin/news/edit', 'title' => '编辑'],
                            ['name' => 'weixin/news/del', 'title' => '删除'],
                            ['name' => 'weixin/news/multi', 'title' => '批量更新']
                        ]
                    ],
                    [
                        'name'    => 'weixin/user/index',
                        'title'   => '微信用户',
                        'extend'  => 'padding-left: 15px;',
                        'icon'    => 'fa fa-angle-double-right',
                        'ismenu'  => 1,
                        'sublist' => [
                            ['name' => 'weixin/user/sendmsg',         'title' => '推送消息'],
                            ['name' => 'weixin/user/edit_user_tag',   'title' => '修改用户标签'],
                            ['name' => 'weixin/user/edit_user_group', 'title' => '修改用户分组'],
                        ]
                    ],
                    [
                        'name'    => 'weixin/user/tag',
                        'title'   => '用户标签',
                        'extend'  => 'padding-left: 15px;',
                        'icon'    => 'fa fa-angle-double-right',
                        'ismenu'  => 1,
                        'sublist' => [
                            ['name' => 'weixin/user/tagadd',   'title' => '添加'],
                            ['name' => 'weixin/user/tagedit',  'title' => '编辑'],
                            ['name' => 'weixin/user/tagdel',   'title' => '删除'],
                        ]
                    ],
                    [
                        'name'    => 'weixin/fans/index',
                        'title'   => '粉丝用户',
                        'extend'  => 'padding-left: 15px;',
                        'icon'    => 'fa fa-angle-double-right',
                        'ismenu'  => 1,
                        'sublist' => [
                            ['name' => 'weixin/fans/syncwechatfans',   'title' => '同步粉丝'],
                            ['name' => 'weixin/fans/sendmsg',          'title' => '推送消息'],
                        ]
                    ]
                ]
            ]
        ];

        Menu::create($menu);
    }

    /**
     * 插件卸载方法
     * @return bool
     */
    public function uninstall()
    {
        Menu::delete('weixin');
        return true;
    }
    
    /**
     * 插件启用方法
     */
    public function enable()
    {
        Menu::enable('weixin');
    }

    /**
     * 插件禁用方法
     */
    public function disable()
    {
        Menu::disable('weixin');
    }

}
